package practicedemo41;

public class PhoneNumberTest {
    public static void main(String[] args) {
        PhoneNumber p1 = new PhoneNumber("17387520730");
        System.out.println(PhoneNumberHide(p1.getNumber()));
        System.out.println(NewPhoneNumberHide(p1.getNumber()));
    }

    //古典方法,自己写的实现的
    public static String PhoneNumberHide(String phoneNumber) {
        String arr = "";
        for (int i = 0; i < phoneNumber.length(); i++) {
            if (i >= 3 && i <= 6) {
                arr += "*";
                continue;
            }
            arr += phoneNumber.charAt(i);
        }
        return arr;
    }
    //新方法，采用String substring(int beginIndex,int endIndex) 截取
    //注意是包头不包尾
    public static String NewPhoneNumberHide(String phoneNumber){
        //获取手机号码前三位
        String arr1 =  phoneNumber.substring(0,3);
        //后四位
        String arr2 = phoneNumber.substring(7);

        for (int i = 0; i < 4; i++) {
            arr1 += "*";
        }
        arr1 += arr2;
        return arr1;
    }
}
